from concurrent.futures import ThreadPoolExecutor
from missav.test_redis import RedisConn
r = RedisConn()
def down_video(url_t):
   for i in range(3):
       try:
           from missav.get_m3u8_3 import down
           print("movie_url", url_t)
           down(url_t)
       except Exception as e:
           print("down video \t", e)
           continue
       else:
           print("下载完成 down_video")
           break
if __name__ == '__main__':

    # with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
    #     executor.map(down_video, url_list_movie)
    import psutil



    threadPool = ThreadPoolExecutor(max_workers=10, thread_name_prefix="test_")
    for i in r.get_all("movie_detail1"):
        # flag = r.add("movie_detail2",i)
        # if flag:
        usage = psutil.disk_usage(r"E:")
        if usage.free > 20 * 1024 ** 3:
            print("多线程")
            future =threadPool.submit(down_video, i)
        else:
            print("单线程")
            down_video(i)

        if usage.free < 3 * 1024 ** 3:
            import os
            os._exit(os.EX_OK)
    threadPool.shutdown(wait=True)
